/* GUI CONVERTED from reoptr1i.p (converter v1.75) Sat Aug 12 23:07:39 2000 */
/* reoptr1i.p - LABOR REJECT TRANSACTION BY PART (Sub Procedure)        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 8.5      LAST MODIFIED: 05/30/96              BY: lal *J0PN*/
/* REVISION: 8.5    LAST MODIFIED: 12/26/96 BY: *H0Q8* Julie Milligan   */
/* REVISION: 8.5    LAST MODIFIED: 12/11/97 BY: *H1H6* Manmohan Pardesi */


/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */

         {mfdeclre.i}
         {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reoptr1i_p_1 "Modify Backflush"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1i_p_2 "Elapsed or Stop Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1i_p_3 "Conv"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1i_p_4 "BOM"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1i_p_5 "Routing"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1i_p_6 "Start Time"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

         define buffer ophist for op_hist.

         define variable yn like mfc_logical.
         define variable start_setup as character format "99:99:XX"
            label {&reoptr1i_p_6}.
         define variable start_run like start_setup.
         define variable stop_setup like start_setup
            label {&reoptr1i_p_2}.
         define variable stop_run like stop_setup.
         define variable rsn_desc1 like rsn_desc.
         define variable locked-file as character.
         define variable msg-counter as integer no-undo.
         define variable um like pt_um.
         define variable tot_units like op_qty_comp.
         define variable disp_units as character format "x(15)".

         define shared variable wc_recno as recid.
         define shared variable op_recno as recid.
         define shared variable wr_recno as recid.
         define shared variable wo_recno as recid.
         define shared variable ophist_recid as recid.
/*H0Q8*  define shared variable inv-issued as logical no-undo. */
/*H0Q8*/ define variable inv-issued as logical no-undo.
         define shared variable last_date like op_date.
         define shared variable site like rps_site no-undo.
         define shared variable prline like rps_line no-undo.
         define shared variable bom_code as character format "x(18)"
            label {&reoptr1i_p_4}.
         define shared variable routing as character format "x(18)"
            label {&reoptr1i_p_5}.
         define shared variable mod_issrc like mfc_logical
            label {&reoptr1i_p_1}.
         define shared variable global_rsntyp as character.
         define shared variable conv like um_conv label {&reoptr1i_p_3}.
/*N002*/ define variable entered_qty_rjct as decimal no-undo.
/*N002*/ define variable conv_factor as decimal no-undo.
/*N002*/ define variable undo_stat like mfc_logical no-undo.
/*N002*/ define variable result_status as character no-undo.
/*N002*/ define variable consider_output_qty like mfc_logical no-undo.
/*N002*/ define variable tracing_enabled like mfc_logical no-undo.
/*N002*/ define shared variable h_wiplottrace_procs as handle no-undo.
/*N002*/ define shared variable h_wiplottrace_funcs as handle no-undo.
/*N002*/ {wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
/*N002*/ {wlcon.i} /*CONSTANTS DEFINITIONS*/

         define shared frame a.

         /* Input frame definitions */
         {reopf11a.i}

         /* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION */
         {gpxpld01.i "shared"}

         {gpglefv.i}

                  /* Re-find Work Order and Routing records */
                  find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
                  find wr_route no-lock where recid(wr_route) = wr_recno.
                  find pt_mstr where pt_part = wr_part no-lock no-error.

                  do
                  transaction
                  with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


                     create op_hist.

                     {mfnoptr.i}

                     assign op_wo_nbr = wr_nbr
                             op_wo_op = wr_op
                            op_wo_lot = wr_lot
                              op_type = "LABOR"
                         op_tran_date = today
                             op_wkctr = wr_wkctr
                               op_mch = wr_mch
                              op_date = last_date
                              op_site = site
                              op_line = prline
                         op_milestone = wr_milestone
                              op_part = wr_part.

                            op_std_setup = wr_setup.
                            op_std_run = wr_run.

                     ophist_recid = recid(op_hist).
                         op_recno = recid(op_hist).

                     start_run = "000000".
                     stop_run = "000000".

                     um = pt_um.
                     conv = 1.
/*H1H6*/             bombatch = 1.

                     display op_wkctr op_mch
                     wr_qty_wip
                     op_qty_rjct
                     um conv " " @ disp_units
                     mod_issrc
                     op_trnbr format ">>>>>>>9".

/*N002*/             if is_wiplottrace_enabled() then do:
/*N002*/                run init_bkfl_input_wip_lot_temptable
/*N002*/                in h_wiplottrace_procs.
/*N002*/
/*N002*/                run init_bkfl_output_wip_lot_temptable
/*N002*/                in h_wiplottrace_procs.
/*N002*/
/*N002*/                run init_reject_wip_lot_temptable
/*N002*/                in h_wiplottrace_procs.
/*N002*/             end.

                     /* Added section */
                     if not wr_milestone then do:
                        find first wr_route no-lock where wr_lot = wo_lot
                        and wr_op > input op_wo_op no-error.
                        if available wr_route then do:
                           {mfmsg.i 560 2}
                        end.
                        find wr_route no-lock where recid(wr_route) = wr_recno.
                     end.
                     /* End of added section */

                     find wc_mstr where wc_wkctr = op_wkctr
                     and wc_mch = op_mch no-lock no-error.
                     if available wc_mstr then do:
                        display wc_desc.
                        find dpt_mstr no-lock where dpt_dept = wc_dept no-error.
                        if available dpt_mstr then do:
                           op_dept = wc_dept.
                           display op_dept dpt_desc.
                        end.
                        else display " " @ dpt_desc.
                     end.
                     else display " " @ wc_desc " " @ op_dept " " @ dpt_desc.

                     global_rsntyp = "reject".

/*N002*/             if is_wiplottrace_enabled() and
/*N002*/             is_operation_queue_lot_controlled
/*N002*/             (wr_lot, wr_op, OUTPUT_QUEUE) then
/*N002*/                 tracing_enabled = yes.
/*N002*/             else
/*N002*/                 tracing_enabled = no.

                     set_ophist:
                     do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


                        set op_wkctr op_mch op_dept op_emp op_shift
                        op_qty_rjct
                        um conv
                        op_rsn_rjct
/*N002*/                   when (not tracing_enabled)
                        mod_issrc
                        editing:

                           if frame-field = "op_wkctr"
                           or frame-field = "op_mch" then do:
                              {mfnp.i wc_mstr op_wkctr wc_wkctr
                               op_wkctr wc_wkctr wc_wkctr}
                              if recno <> ? then do:
                                 display wc_wkctr @ op_wkctr
                                   wc_mch @ op_mch wc_desc.

                                 find dpt_mstr no-lock where
                                 dpt_dept = wc_dept no-error.
                                 if available dpt_mstr then do:
                                    op_dept = dpt_dept.
                                    display op_dept dpt_desc.
                                 end.
                                 else display " " @ dpt_desc.
                              end.
                           end.
                           else if frame-field = "op_dept" then do:
                               {mfnp.i dpt_mstr op_dept dpt_dept
                                op_dept op_dept dpt_dept}
                               if recno <> ? then
                               display dpt_dept @ op_dept dpt_desc.
                           end.
                           else if frame-field = "op_emp" then do:
                              {mfnp.i emp_mstr op_emp emp_addr
                               op_emp emp_addr emp_addr}
                              if recno <> ? then do:
                                 display emp_addr @ op_emp
                                 emp_fname + " " + emp_lname @ ad_name.
                              end.
                           end.
                           else if frame-field = "op_rsn_rjct" then do:
                              {mfnp01.i rsn_ref op_rsn_rjct rsn_code
                               ""reject"" rsn_type rsn_type}
                              if recno <> ? then
                                 display rsn_code @ op_rsn_rjct
                                 rsn_desc @ rsn_desc1.
                           end.
                           else do:
                              ststatus = stline[3].
                              status input ststatus.
                              readkey.
                              apply lastkey.
                           end.
                        end.

/*N002*/                entered_qty_rjct = op_qty_rjct.

                        find wc_mstr where wc_wkctr = op_wkctr
                        and wc_mch = op_mch no-lock no-error.
                        if not available wc_mstr then do:
                           {mfmsg.i 519 3} /* Work center does not exist */
                           undo, retry.
                        end.
                        display wc_desc.
                        wc_recno = recid(wc_mstr).

                        find dpt_mstr where dpt_dept = op_dept no-lock no-error.
                        if not available dpt_mstr then do:
                           next-prompt op_dept.
                           {mfmsg.i 532 3} /* Department does not exist */
                           undo, retry.
                        end.
                        display dpt_desc.

                        if op_emp > "" then do:
                           find emp_mstr where emp_addr = op_emp
                           no-lock no-error.
                           if not available emp_mstr then do:
                            {mfmsg.i 520 2} /* Employee number does not exist */
                              display " " @ ad_name.
                           end.
                           else display emp_fname + " " + emp_lname @ ad_name.

                           if available emp_mstr
                           and lookup(emp_status,"AC,PT") = 0 then do:
                              next-prompt op_emp.
                            {mfmsg.i 4027 3} /* Employee not on active status */
                              undo,retry.
                           end.
                        end.
                        else display " " @ ad_name.

                        /* Added section */
                        if um <> pt_um or conv <> 1 then do:
                           if not conv entered then do:
                              {gprun.i ""gpumcnv.p""
                             "(um, pt_um, op_part, output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                              if conv = ? then do:
                                 {mfmsg.i 33 2}
                                 conv = 1.
                              end.
                              display conv with frame a.
                           end.
                           tot_units = op_qty_rjct * conv.
                           disp_units = string(tot_units,"->,>>>,>>9.9<<<<<<<<")
                              + " " + pt_um.
                           disp_units = fill(" ",max(15 - length(disp_units),0))
                             + disp_units.
                           display disp_units with frame a.
                        end.
                        else display conv " " @ disp_units with frame a.
                        /* End of added section */

                        find rsn_ref where rsn_code = op_rsn_rjct
                        and rsn_type = "reject" no-lock no-error.
                        if available rsn_ref then
                           display rsn_desc @ rsn_desc1.
                        else
                        do:
                           display " " @ rsn_desc1.
                           if op_rsn_rjct > "" then do:
                              {mfmsg.i 534 2}
                           end.
                        end.

                        {gprun.i ""reop11b.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         /*V8+*/

/*N002*/                conv_factor = conv.
/*N002*/
/*N002*/                if is_wiplottrace_enabled()
/*N002*/                and is_operation_queue_lot_controlled
/*N002*/                    (wo_lot, op_wo_op, OUTPUT_QUEUE)
/*N002*/                then do:
/*N002*/                   if is_operation_queue_lot_controlled
/*N002*/                      (wo_lot, op_wo_op, INPUT_QUEUE)
/*N002*/                   then do:
/*N002*/                      run get_bkfl_input_wip_lots_from_user
/*N002*/                      in h_wiplottrace_procs
/*N002*/                      (input wo_lot, input op_wo_op,
/*N002*/                      input entered_qty_rjct,
/*N002*/                      input conv_factor,
/*N002*/                      input um, input site, input op_wkctr, input op_mch,
/*N002*/                      output undo_stat).
/*N002*/
/*N002*/                      if undo_stat then do:
/*N002*/                         undo, retry.
/*N002*/                      end.
/*N002*/                   end.
/*N002*/
/*N002*/                   if entered_qty_rjct <> 0 then do:
/*N002*/                      run get_std_labor_reject_wip_lots_from_user
/*N002*/                      in h_wiplottrace_procs
/*N002*/                      (input wo_lot, input op_wo_op,
/*N002*/                      input entered_qty_rjct,
/*N002*/                      input conv_factor,
/*N002*/                      input um, input op_wo_op,
/*N002*/                      input site, input op_wkctr, input op_mch,
/*N002*/                      output undo_stat).
/*N002*/
/*N002*/                      if undo_stat then do:
/*N002*/                         undo, retry.
/*N002*/                      end.
/*N002*/                   end.
/*N002*/
/*N002*/
/*N002*/                   /*CHECK FOR COMBINED LOTS - INPUT WIP AND COMPONENTS
/*N002*/                   TO A PARTICULAR REJECT WIP LOT*/
/*N002*/
/*N002*/                   run std_labor_chk_combnd_lots_in_rjct
/*N002*/                   in h_wiplottrace_procs
/*N002*/                   (input wo_lot,
/*N002*/                   input op_wo_op,
/*N002*/                   input conv_factor,
/*N002*/                   output result_status).
/*N002*/
/*N002*/                   if result_status = FAILED_EDIT then do:
/*N002*/                      view frame a.
/*N002*/                      view frame bkfl1.
/*N002*/                      undo, retry.
/*N002*/                   end.
/*N002*/
/*N002*/
/*N002*/
/*N002*/                   /*CHECK FOR SPLIT LOTS - OUTPUT WIP, REJECT WIP
/*N002*/                   TO A PARTICULAR INPUT WIP LOT*/
/*N002*/
/*N002*/                   consider_output_qty = yes.
/*N002*/
/*N002*/                   run std_labor_check_for_split_lots
/*N002*/                   in h_wiplottrace_procs
/*N002*/                   (input wo_lot,
/*N002*/                   input op_wo_op,
/*N002*/                   input conv_factor,
/*N002*/                   input consider_output_qty,
/*N002*/                   output result_status).
/*N002*/
/*N002*/                   if result_status = FAILED_EDIT then do:
/*N002*/                      view frame a.
/*N002*/                      view frame bkfl1.
/*N002*/                      undo, retry.
/*N002*/                   end.
/*N002*/                end.

                        yn = yes.
         /*V8+*/       {mfgmsg10.i 12 1 yn} /* is all info correct*/   
                        if yn <> yes then undo, retry.

/*H0Q8*                 {gprun.i ""reoptr1f.p""} */
/*H0Q8*/                {gprun.i ""reoptr1f.p"" "(input """",
                                                  output inv-issued)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                        if inv-issued then undo, retry.
                     end.
/*GUI*/ if global-beam-me-up then undo, leave.


                     /* Added section */
                     msg-counter = 0.
                     repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

                        release wo_mstr.
                        release wr_route.
                        find wo_mstr exclusive-lock
                           where recid(wo_mstr) = wo_recno no-wait no-error.
                        if available wo_mstr then do:
                           find wr_route exclusive-lock
                           where recid(wr_route) = wr_recno
                           no-wait no-error.
                        end.
                        if locked wo_mstr
                        or locked wr_route
                        then do:
                           if locked wo_mstr then locked-file = "wo_mstr".
                           else
                           if locked wr_route then locked-file = "wr_route".
                           if msg-counter modulo 100 = 0 then do:
                              {mfmsg03.i 1400 1 locked-file
                                kblabel(""end-error"") """"
                                "fill(""."",(msg-counter / 100) mod 20)" }
                              readkey pause 1.
         /*V8+*/              if keyfunction(lastkey) = "end-error" then undo,
                              leave.   
                              apply lastkey.
                           end.
                           msg-counter = msg-counter + 1.
                           next.
                        end.
                        if available wo_mstr and available wr_route then leave.
                     end.
/*GUI*/ if global-beam-me-up then undo, leave.

                     hide message.
         /*V8+*/
                     /* End of added section */

                     wr_qty_rjct = wr_qty_rjct + op_qty_rjct.

                     {gprun.i ""reoptrc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


                     /* Post non-milestone operations at standard */
                     {gprun.i ""reoptr1c.p""
                     "(wr_lot, wr_op, ""LABOR"", wo_recno,
                       op_date, op_shift, op_qty_rjct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                     /* UPDATE REPETITIVE SCHEDULE - Routing & Components */
                     {gprun.i ""reoptra.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


                     if mod_issrc = no then
                     for each pk_det exclusive-lock where pk_user = mfguser:
                        pk_qty = (pk_qty * op_qty_rjct) / bombatch.
                     end.

                     /* CREATE INVENTORY TRANSACTIONS FOR COMPONENTS ISSUED */
                     {gprun.i ""rewois.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


/*N002*/             /*BACKFLUSH LIST OF INPUT WIP LOTS AND OUTPUT WIP LOTS. */
/*N002*/
/*N002*/             if is_wiplottrace_enabled()
/*N002*/             and is_operation_queue_lot_controlled
/*N002*/                 (wr_lot, wr_op, OUTPUT_QUEUE)
/*N002*/             then do:
/*N002*/                for first op_hist
/*N002*/                where recid(op_hist) = ophist_recid
/*N002*/                no-lock: end.
/*N002*/
/*N002*/                run std_labor_backflush_wip_lots in h_wiplottrace_procs
/*N002*/                (input op_trnbr, input wr_lot, input wr_op,
/*N002*/                input conv_factor,
/*N002*/                input op_site, input op_wkctr, input op_mch).
/*N002*/
/*N002*/                if entered_qty_rjct <> 0 then do:
/*N002*/                   run std_labor_reject_wip_lots in h_wiplottrace_procs
/*N002*/                   (input ophist_recid,
/*N002*/                   input conv_factor,
/*N002*/                   input op_wkctr,
/*N002*/                   input op_mch).
/*N002*/                end.
/*N002*/             end.
/*GUI*/ if global-beam-me-up then undo, leave.

                  end.
